package com.example.androidmvvmdemo.view;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.example.androidmvvmdemo.R;
import com.example.androidmvvmdemo.databinding.ActivityMainBinding;
import com.example.androidmvvmdemo.viewModel.ImageOperationVM;

public class MainActivity extends AppCompatActivity {

    private static final String IMAGE_URL = "http://imglf6.nosdn0.126.net/img/T2xtRUpvNXdwUVJWQm1QR2s2eklMNTZiOWxuYmxabmI3V1JaYW9KbHJNZ1VvZVVsMWp3WnB3PT0.jpg?imageView&thumbnail=266y200&type=jpg&quality=96&stripmeta=0&type=jpg";
    private ActivityMainBinding activityMainBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        initData();
    }

    private void initData() {
        activityMainBinding.setDownload(this);
        activityMainBinding.setImage(ImageOperationVM.getImageModel());
    }

    public void downloadImage(View v) {
        ImageOperationVM.download(IMAGE_URL);
    }
}

